{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "584f7c00-08a1-4776-a29a-a4e9095fcf48",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "aad799ff-7a71-4c3c-883c-9c7d5b504c10",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "train_data = pd.read_csv('基于近红外光谱的煤质参数预测挑战赛公开数据/train_data.csv')\n",
    "train_label = pd.read_csv('基于近红外光谱的煤质参数预测挑战赛公开数据/train_label.csv')\n",
    "\n",
    "test_data = pd.read_csv('基于近红外光谱的煤质参数预测挑战赛公开数据/test_data.csv')\n",
    "submit = pd.read_csv('提交示例.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "06b6d303-accd-4aad-84ee-8b3e225714b7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((100, 126), (500, 126))"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data.shape, train_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f56185c0-f1cc-46e9-9795-4b394254ca24",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>样品编号</th>\n",
       "      <th>水分</th>\n",
       "      <th>灰分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>12.2</td>\n",
       "      <td>6.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>11.7</td>\n",
       "      <td>6.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>9.0</td>\n",
       "      <td>29.58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>7.6</td>\n",
       "      <td>22.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>14.4</td>\n",
       "      <td>19.87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   样品编号    水分     灰分\n",
       "0     0  12.2   6.04\n",
       "1     1  11.7   6.03\n",
       "2     2   9.0  29.58\n",
       "3     3   7.6  22.95\n",
       "4     4  14.4  19.87"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_label.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "62faf00b-b406-4e14-b788-bb227c1c7928",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "m = LinearRegression()\n",
    "m.fit(train_data.iloc[:, 1:], train_label['水分'])\n",
    "submit['水分'] = m.predict(test_data.iloc[:, 1:])\n",
    "\n",
    "m = LinearRegression()\n",
    "m.fit(train_data.iloc[:, 1:], train_label['灰分'])\n",
    "submit['灰分'] = m.predict(test_data.iloc[:, 1:])\n",
    "\n",
    "submit.to_csv('lr.csv', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36ed68c8-e3f6-42ba-afb1-4ffc02885968",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3.10"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
